Ext.define('dg.controller.usuarios.CtrUsuario', {
    extend: 'Ext.app.Controller',

    stores:['usuarios.StoreUsuarios'],

	views:['usuarios.PanelUsuarios',
        'usuarios.form.ComboUsuarios',
        'usuarios.GridUsuarios',
        'usuarios.form.FormUsuarios'],
	
	init: function (){
	
		console.info("Ctr de usuarios cargado!");
		
		
		this.control({
			panelusuarios:{
				agregar: this.mostrarVentana,
				editar: this.editarUsuario
			}
		});
		
		return Ext.create('dg.view.usuarios.PanelUsuarios',{
			title: 'Nuevo Titulo'/*,
			listeners:{
				agregar: function (){
					alert("Agregar usuario!");
				}
			}*/
		});
	},
	
	editarUsuario: function (panel, botn, cmd, record){
		/*Ext.ModelManager.getModel('dg.model.usuarios.UsuarioModel').load(123, {
		    success: function(user) {
		        console.log(user);//.getId()); //salida en consola 123
		    }
		});*/
	},
	
	mostrarVentana: function (panelusuarios,botonagregar,title){
				
		var usuario = new Ext.create('dg.model.usuarios.UsuarioModel',{
			//id_usuario: 3,
			nombre:'Josue Hernandez',
			genero:1,
			id_rol:''
		});
		usuario.save();
		
		return ;
		
		
		if(! this.window)
		//si la ventana no se ha creado
			this.window= Ext.create('Extmx.form.WindowForm',{
                title:title+' usuario',
                //width: 640,
                xtypeForm:'formusuarios',
                titleBtnGuarda: 'Guardar usuario'
                /*,
				listeners:{
					scope: this,
					/* Creacion y renderizado * /
					added: function (){ console.info("added");},
					beforeactivate: function (){ console.info("beforeactivate");},
					beforerender: function (){ console.info("beforerender");},
					render: function (){ console.info("render");},
					afterrender: function (){ console.info("afterrender");},
					beforeshow: function (){ console.info("beforeshow");},
					show: function (){ console.info("show"); },
					activate: function (){ console.info("activate");},
					boxready: function (){ console.info("boxready");},
					resize: function (){ console.info("resize");},
					afterlayout: function (){ console.info("afterlayout");},
					
					add:function (){ console.info("add");},
					
					beforeadd: function (){ console.info("beforeadd");},
					beforeclose: function (){ console.info("beforeclose");},
					beforecollapse: function (){ console.info("beforecollapse");},
					beforedeactivate: function (){ console.info("beforedeactivate");},
					beforedestroy: function (){ console.info("beforedestroy");},
					beforeexpand: function (){ console.info("beforeexpand");},
					beforehide: function (){ console.info("beforehide");},
					beforeremove: function (){ console.info("beforeremove");},
					
					
					beforestaterestore: function (){ console.info("beforestaterestore");},
					beforestatesave: function (){ console.info("beforestatesave");},
					blur: function (){ console.info("blur");},
					bodyresize: function (){ console.info("bodyresize");},
					
					close: function (){ console.info("close");},
					collapse: function (){ console.info("collapse");},
					deactivate: function (){ console.info("deactivate");},
					destroy: function (){ console.info("destroy");},
					disable: function (){ console.info("disable");},
					enable: function (){ console.info("enable");},
					expand: function (){ console.info("expand");},
					focus: function (){ console.info("focus");},
					hide: function (){ console.info("hide");},
					iconchange: function (){ console.info("iconchange");},
					iconclschange: function (){ console.info("iconclschange");},
					move: function (){ console.info("move");},
					remove: function (){ console.info("remove");},
					removed: function (){ console.info("removed");}

				}*/
			});
			



        this.window.show(botonagregar.id);

        this.window.setTitle(title+' usuario');

	}
	
});